#include "ShiftRegister.h"

void ShiftRegister_Send8(uint8 cByte)
{
	ShiftRegister_Shift8(cByte);
	ShiftRegister_Latch();
}

void ShiftRegister_Send16(uint16 iByte)
{
	ShiftRegister_Shift8( (uint8)(iByte) );
	ShiftRegister_Shift8( (uint8)(iByte>>8) );
	ShiftRegister_Latch();
}
void ShiftRegister_Send32(uint32 dByte)
{
	uint8 cByte0;
	uint8 cByte1;
	uint8 cByte2;
	uint8 cByte3;
	cByte0 = (uint8)dByte;
	cByte1 = (uint8)(dByte>>8);
	cByte2 = (uint8)(dByte>>16);
	cByte3 = (uint8)(dByte>>24);
	ShiftRegister_Shift8( cByte0 );
	ShiftRegister_Shift8( cByte1 );
	ShiftRegister_Shift8( cByte2 );
	ShiftRegister_Shift8( cByte3 );
	ShiftRegister_Latch();
}

void ShiftRegister_Shift8(uint8 cByte)
{
	uint8 cIndex;
	uint8 cBuffer = cByte;
	for ( cIndex = 0, cIndex < 8, cIndex++ )
	{
		ShiftRegister_Pin_SDI.write( cBuffer&1 );
		cBuffer = cBuffer >> 1;
		ShiftRegister_Clock();
	}
}
	
void ShiftRegister_Latch(void)
{
	ShiftRegister_Pin_LE.write(1);
	ShiftRegister_Pin_LE.write(0);
}

void ShiftRegister_Clock(void)
{
	ShiftRegister_Pin_CLK.write(1);
	ShiftRegister_Pin_CLK.write(0);
}